package com.lxd.property.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lxd.property.pojo.Staff;
import com.lxd.property.service.StaffService;
import com.lxd.property.utils.Page;

@Controller
@RequestMapping("staff")
public class StaffController {

	@Autowired
	private StaffService staffService;

	@RequestMapping(value = "findAllStaff", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> findAllDepartment(Page pageUtil, 
			@RequestParam(value = "s_name", required = false) String s_name,
			@RequestParam(value = "s_dename", required = false) String s_dename) {
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("start", pageUtil.getStart());
		map.put("rows", pageUtil.getRows());
		map.put("s_name", s_name);
		map.put("s_dename", s_dename);
		map.put("state1", 0);

		return staffService.findAllStaff(map);

	}

	@RequestMapping(value = "addStaff", method = RequestMethod.POST)
	@ResponseBody
	public Boolean addStaff(Staff staff){

		return staffService.addStaff(staff) == 1;

	}

	@RequestMapping(value = "findStaffById", method = RequestMethod.POST)
	@ResponseBody
	public Staff findStaffById(Integer id) {

		return staffService.findStaffById(id);

	}

	@RequestMapping(value = "updateStaff", method = RequestMethod.POST)
	@ResponseBody
	public Boolean updateStaff(Staff staff){
		return staffService.updateStaff(staff) == 1;

	}

	@RequestMapping(value = "staffQuit", method = RequestMethod.POST)
	@ResponseBody
	public Boolean staffQuit(Staff staff) {
		return staffService.staffQuit(staff) == 1;
	}
	
	
	@RequestMapping(value = "findAllDepartureStaff.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> findAllDepartureStaff(Page pageUtil, 
			@RequestParam(value = "s_name", required = false) String s_name,
			@RequestParam(value = "s_dename", required = false) String s_dename) {
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("start", pageUtil.getStart());
		map.put("rows", pageUtil.getRows());
		map.put("s_name", s_name);
		map.put("s_dename", s_dename);
		map.put("state1", 1);

		return staffService.findAllStaff(map);

	}
}
